<?php

/**
 * 会员首页
 */

namespace app\member\common;

use app\huitong\common\AccountCommon;

class IndexCommon extends \app\member\common\MemberCommon {

    protected function index() {
        $this->setMeta('会员中心');
        $this->pageInfo['name'] = '会员中心';

        $orderList = target('order/Order')->loadList([
            'order_user_id' => $this->userInfo['user_id']
        ], 5);

        $followList = target('shop/ShopFollow')->loadList([
            'user_id' => $this->userInfo['user_id']
        ], 8);

        $shopFootprint = target('shop/ShopFootprint')->loadFootprint($this->userInfo['user_id'], 5);

        $this->assign('orderList', $orderList);
        $this->assign('followList', $followList);
        $this->assign('shopFootprint', $shopFootprint);

        $this->assign('orderCount', [
            'pay' => $this->countOrder(1),
            'delivery' => $this->countOrder(2),
            'complete' => $this->countOrder(3),
        ]);

        $this->memberDisplay();
    }


    protected function countOrder($type) {

        $where = [];
        $where['B.order_status'] = 1;
        $where['B.order_user_id'] = $this->userInfo['user_id'];


        switch ($type) {
            case 1:
                $where['B.pay_type'] = 1;
                $where['B.pay_status'] = 0;
                $where['delivery_status'] = 0;
                break;
            case 2:
                $where['_sql'][] = '(B.pay_type = 0 OR B.pay_status = 1)';
                $where['delivery_status'] = 0;
                break;
            case 3:
                $where['delivery_status'] = 1;
                $where['order_complete_status'] = 0;
                break;
            case 4:
                $where['order_complete_status'] = 1;
                $where['comment_status'] = 0;
                break;
        }

        $model = target('shop/ShopOrder');

        return $model->countList($where);

    }

}